<template>
  <div class="login-page">
    <el-card class="login-card">
      <div class="login-header">
        <h1>登录</h1>
      </div>
      <el-form :model="form" :rules="rules" ref="formRef" class="login-form">
        <el-form-item prop="email">
          <el-input
            v-model="form.email"
            placeholder="邮箱"
            prefix-icon="el-icon-user"
            size="large"
            class="login-input"
          />
        </el-form-item>

        <el-form-item prop="password">
          <el-input
            v-model="form.password"
            type="password"
            placeholder="密码"
            prefix-icon="el-icon-lock"
            size="large"
            class="login-input"
          />
        </el-form-item>

        <el-form-item>
          <el-button
            type="primary"
            size="large"
            class="login-button"
            @click="handleSubmit"
          >
            登录
          </el-button>
        </el-form-item>
      </el-form>
      <div class="login-footer">
        <el-button class="forgot-password" @click="handleForgotPassword">
          忘记密码？
        </el-button>
      </div>
    </el-card>
  </div>
</template>
<script setup>
import { ref } from "vue";

import { useRouter } from "vue-router";

const router = useRouter();

const rules = {
  email: [
    { required: true, message: "请输入邮箱", trigger: "blur" },
    { type: "email", message: "请输入有效的邮箱地址", trigger: "blur" },
  ],
  password: [
    { required: true, message: "请输入密码", trigger: "blur" },
    { min: 6, message: "密码长度不能少于6个字符", trigger: "blur" },
  ],
};
const formRef = ref(null);
const form = ref({
  email: "",
  password: "",
});
const handleSubmit = () => {
  formRef.value.validate(async (valid) => {
    if (valid) {
      router.replace("/");
    }
  });
};
const handleForgotPassword = () => {
  alert("忘记密码功能待实现");
};
</script>

<style scoped>
.login-page {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background: #f4f6f9;
}

.login-card {
  width: 360px;
  padding: 20px;
  border-radius: 12px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  background-color: #ffffff;
}

.login-header {
  text-align: center;
  margin-bottom: 20px;
}

.login-header h1 {
  font-size: 24px;
  color: #333;
}

.login-form {
  margin-top: 20px;
}

.login-input {
  border-radius: 8px;
  background-color: #f9f9f9;
  border: 1px solid #e0e0e0;
}

.login-button {
  width: 100%;
  border-radius: 8px;
  background-color: #409eff;
  border-color: #409eff;
}

.login-footer {
  margin-top: 20px;
  text-align: center;
}

.forgot-password {
  color: #409eff;
  font-size: 14px;
}
</style>
